﻿using System;
using System.Collections.Generic;
using System.Linq;
using DomainModel;
using Repository.Abstract;
using Services.Abstract;

namespace Services.Concrete
{
    public class SubgroupService : Service<Subgroup>, ISubgroupService
    {
        private readonly ISubgroupRepository _subgroupRepository;

        public SubgroupService(ISubgroupRepository subgroupRepository)
            : base(subgroupRepository)
        {
            _subgroupRepository = subgroupRepository;
        }

        public List<Subgroup> GetSubgroups(Group group)
        {
            if (group == null)
                throw new ArgumentNullException("group");

            return _subgroupRepository.GetByGroup(group).ToList();
        }

        public Subgroup GetSubgroup(Group group, int subgroupNo)
        {
            if (group == null || subgroupNo <= 0)
                throw new ArgumentNullException("group");

            return _subgroupRepository.GetByGroupAndNo(group, subgroupNo);
        }

        /*public Subgroup GetSubgroup(Group group, int subgroupNo)
        {
            if (group == null || subgroupNo <= 0)
                return null;

            return DAOFactory.DEFAULT.SubgroupDAO.GetByGroupAndNo(group, subgroupNo);
        }

        public List<Subgroup> GetSubgroup(Group group)
        {
            if (group == null)
                return null;

            return DAOFactory.DEFAULT.SubgroupDAO.GetByGroup(group).ToList();
        }

        public void Save(Subgroup entity)
        {
            if (entity == null)
                return;

            DAOFactory.DEFAULT.SubgroupDAO.SaveOrUpdate(entity);
        }

        public void Delete(Subgroup entity)
        {
            if (entity == null)
                return;

            DAOFactory.DEFAULT.SubgroupDAO.Delete(entity);
        }

        public Subgroup GetById(long id)
        {
            if (id <= 0)
                return null;

            return DAOFactory.DEFAULT.SubgroupDAO.GetById(id);
        }

        public List<Subgroup> GetAll()
        {
            return DAOFactory.DEFAULT.SubgroupDAO.GetAll().ToList();
        }*/
    }
}